﻿using System;
using System.Reflection;

namespace 案例3
{
    class Program
    {
        public static void Print(Object[] objs)
        {
            Type type = objs[0].GetType();
            Console.WriteLine(type);
            PropertyInfo[] properties = type.GetProperties();
            foreach (Object obj in objs)
            {
                foreach (PropertyInfo property in properties)
                {
                    Console.Write(property.Name + ":" + property.GetValue(obj)+"\t");
                }
                Console.WriteLine();
            }
            Console.WriteLine();
        }

        static void Main(string[] args)
        {
            Student[] students = { new Student("001", "张三", "男",20), new Student("002", "李四", "男",21) };
            Course[] courses = { new Course("001", "Java", 5), new Course("002", "C#", 2) };
            Print(students);
            Print(courses);
        }
    }
}
